var isSubmit = true;
var isShowFindPassword = false;
var isNotInitPage = false;
var referisError = false;
function loginGome(e) {
    if (!isSubmit) {
        return false
    }
    if (typeof e == "fucntion") {
        if (!e()) {
            return
        }
    }
    var r = $("#frm #loginName").val();
    var i = $("#frm #loginPassword").val();
    $(".findpassword").hide();
    if ($.trim(r) == "") {
        $("#err-tip p").html("请输入您的用户名");
        $("#err-tip").show();
        $("#frm #loginName").removeClass("txt-focus").addClass("txt-error");
        $("#frm #loginPassword").removeClass("txt-error");
        $("#frm #authenticCodeForLogin").removeClass("txt-error");
        return
    } else if ($.trim(i) == "") {
        $("#err-tip p").html("请输入您的密码");
        $("#err-tip").show();
        $("#loginPassword").addClass("txt-error");
        $("#frm #authenticCodeForLogin").removeClass("txt-error");
        return
    } else if (isNotInitPage || referisError) {
        $("#err-tip").show();
        return
    } else {
        $("#err-tip").hide();
        $("#frm #loginPassword").removeClass("txt-error")
    }
    if ($("#captchaDiv").is(":visible")) {
        if (null != $("#authenticCodeForLogin").val()) {
            if ($("#authenticCodeForLogin").val().length == 0) {
                $("#err-tip p").html("请输入验证码");
                $("#err-tip").show();
                $("#authenticCodeForLogin").addClass("txt-error");
                return
            }
            if ($("#authenticCodeForLogin").val().length > 0 && $("#authenticCodeForLogin").val().length != 4) {
                $("#err-tip p").html("验证码错误，请重新输入");
                $("#err-tip").show();
                $("#authenticCodeForLogin").addClass("txt-error");
                return
            }
        }
    }
    var s = $("#frm #loginType").val();
    var a = {url: contextPath + "/randomLogin.no", type: "post", dataType: "json", beforeSend: function() {
            $(".btnnuw").attr("disabled", "disabled").val("正在登录...");
            isSubmit = false
        }, success: function(e) {
            if (e.code == 200) {
                var r = e.externalUrls;
                if (s == 0 || s == 5) {
                    notifyOthers(r, e.successUrl)
                } else {
                    notifyOthers(r, "");
                    if ($("#pageType").val() == "pop") {
                        sendOperationIframe(1)
                    } else if ($("#pageType").val() == "embed") {
                        sendOperationIframe(10)
                    }
                }
            } else {
                $(".btnnuw").removeAttr("disabled").val("登 录");
                isSubmit = true;
                if ("weakpw" == e.codeType) {
                    if (s == 0 || s == 5) {
                        $("#popLogin-ifrWindow").attr("src", "/redirectResetPwd.no?loginType=0");
                        pop.layerShow("nobj", "popLogin-dytscBir")
                    } else {
                        window.location.href = $(callbackHost).val() + "?option_callback=2"
                    }
                    return
                } else {
                    isShowFindPassword = e.isShowFindPassword;
                    showTips(e.codeType, e.message)
                }
            }
        }, error: function(e) {
            isShowFindPassword = false;
            $(".btnnuw").removeAttr("disabled").val("登 录");
            isSubmit = true;
            showTips("system", "登录失败，请稍后再试！！")
        }};
    if (isSubmit) {
        $("#frm").ajaxSubmit(a)
    }
}
$("#j-pop-close").click(function() {
});
function showTips(e, r) {
    var i = "";
    r == "您输入的用户名不存在，请核对后再重新输入" ? i = "此会员卡号不存在，请核对后重新输入" : i = r;
    var s = $("#frm #isFromHqmLogin").val();
    if (s != undefined && $.trim(s) == "true") {
        showHqmTips(e, i)
    } else {
        if (e == "login") {
            $("#warmTips").hide();
            $("#frm #loginName").addClass("txt-error");
            $("#frm #loginPassword").removeClass("txt-error");
            $("#frm #authenticCodeForLogin").removeClass("txt-error");
            $("#verify_tips").hide();
            $("#captchaDefault").show();
            isShowAuthenticCode()
        } else if (e == "password") {
            $("#frm #loginPassword").addClass("txt-error");
            $("#forgetpwdmsg").addClass("blink");
            $("#frm #loginName").removeClass("txt-error");
            $("#frm #authenticCodeForLogin").removeClass("txt-error");
            $("#verify_tips").hide();
            $("#captchaDefault").show();
            isShowAuthenticCode()
        } else if (e == "captcha") {
            $("#verify_tips").hide();
            $("#authenticCodeForLogin").addClass("txt-error");
            $("#frm #loginName").removeClass("txt-error");
            $("#frm #loginPassword").removeClass("txt-error");
            isShowAuthenticCode()
        } else if (e == "ordinary") {
            $("#err-tip p").html(r);
            $("#err-tip").show();
            return false
        } else {
            $("#err-tip p").html("登录失败，请稍后再试");
            $("#err-tip").show();
            $("#frm #loginName").addClass("txt-error");
            $("#frm #loginPassword").removeClass("txt-error");
            $("#frm #authenticCodeForLogin").removeClass("txt-error");
            $("#captchaDefault").show();
            $("#verify_tips").hide();
            isShowAuthenticCode();
            return false
        }
        $("#err-tip p").html(r);
        $("#err-tip").show();
        if (isShowFindPassword) {
            $(".findpassword").show()
        } else {
            $(".findpassword").hide()
        }
    }
}
function showHqmTips(e, r) {
    if (e == "login") {
        if (r.indexOf("请使用新绑定的手机号") >= 0) {
            var i = contextPath + "/login.no";
            r = r + "点击这里<a class='nBlue'  href=" + i + ">登录</a>"
        }
        $("#frm #valiLoginName").show();
        $("#frm #valiLoginName").html("<span class='tips' style='display: block;'>" + r + "</span>");
        $("#loginNameLi").addClass("wrong");
        $("#loginPasswordLi").removeClass("wrong");
        isShowAuthenticCode()
    } else if (e == "password") {
        $("#frm #valiPassword").show();
        $("#frm #valiPassword").html("<span class='tips' style='display: block;'>" + r + "</span>");
        $("#loginPasswordLi").addClass("wrong");
        isShowAuthenticCode()
    } else if (e == "captcha") {
        $("#captchaDiv").show();
        $("#frm #validate_captcha_login_div").html("<span class='tips' style='display: block;'>" + r + "</span>");
        $("#captchaDiv").addClass("wrong")
    } else {
        $("#frm #loginNameLi").show();
        $("#frm #loginNameLi").html("<span class='tips' style='display: block;'>" + "登录失败，请稍后再试" + "</span>");
        $("#loginNameLi").addClass("wrong")
    }
}
var lntip = "用户名/邮箱/手机号码/门店会员卡号";
var ln = $("#loginName");
function blurInput() {
    if ($.trim(ln.val()) != "") {
        ln.removeClass("txt-error")
    }
}
var pw = $("#loginPassword");
function focusPWInput() {
    $("#forgetpwdmsg").removeClass("blink");
    $(".btnnuw").removeAttr("disabled");
    $("#err-tip").hide();
    isSubmit = true;
    if ($.trim(ln.val()) != "") {
        isShowAuthenticCode();
        isShowConflictOrSnsTips()
    }
    $("#pwdDefault").hide();
    $("#verify_tips").hide()
}
function blurPWInput() {
    $(".btnnuw").removeAttr("disabled");
    isSubmit = true;
    $("#capital_tip").hide()
}
function focusCaptchaInput() {
    $("#captchaDefault").hide();
    $("#authenticCodeForLogin").removeClass("txt-error").addClass("txt-focus");
    if ("error" == $("#verify_tips b").attr("class")) {
        $("#codeRefreshControlCenter").click();
        $("#frm #authenticCodeForLogin").val("")
    }
    $("#verify_tips").hide();
    $("#verify_tips b").removeClass("current");
    $("#verify_tips b").removeClass("error")
}
function isShowAuthenticCode() {
    var e = $("#loginName").val();
    var r = $("input[name='gomeOrCoo8']:checked").val();
    if ("coo8" == r) {
        e = $.trim(e) + "@coo8"
    }
    var i = (new Date).getTime();
    var s = contextPath + "/isShowAuthenticCode.no?sendtimestamp=" + i;
    $.ajax({type: "post", url: s, data: {loginName: e}, success: function(e) {
            var r = $.trim(e.result);
            if (e.isNotInitPage == true) {
                showTips(e.codeType, e.message);
                isNotInitPage = true;
                return false
            }
            if (e.referisError == true) {
                showTips(e.codeType, e.message);
                referisError = true;
                return false
            }
            if (r == "false") {
                $("#captchaDiv").hide()
            } else {
                ssesionId = e.ssesionId;
                captchaGrade = e.captchaGrade;
                $("#captchaType").val(captchaGrade);
                $("#codeRefreshControlCenter").click();
                $("#captchaDiv").show();
                $("#target-pic").addClass("pic-wrap pic-wrap-high")
            }
            $("#authenticCodeForLogin").val("");
            defaultVal($("#authenticCodeForLogin"))
        }})
}
function defaultVal(e) {
    if ($.trim(e.val()) != "") {
        e.parent().find(".default").hide()
    } else {
        e.parent().find(".default").show()
    }
}
function isShowConflictOrSnsTips() {
    isShowFindPassword = false;
    var e = $("#loginName").val();
    var r = (new Date).getTime();
    var i = contextPath + "/isConflictOrSnsOrNikeName.no?sendtimestamp=" + r;
    $("#corp-login dd a").removeClass("hover");
    $.ajax({type: "post", url: i, data: {loginName: e}, success: function(r) {
            $.trim(r);
            if (r.isNotInitPage == true) {
                showTips(r.codeType, r.message);
                isNotInitPage = true;
                return false
            }
            if (r.referisError == true) {
                showTips(r.codeType, r.message);
                referisError = true;
                return false
            }
            var i = r.isConflict;
            var s = r.whereFrom;
            var a = r.isEmailAddress;
            var t = r.isMobileNumber;
            var o = r.isNikename;
            if (i == true) {
                $("#gome-coo8-tips").show()
            } else {
                $("#gome-coo8-tips").hide()
            }
            if (o == true) {
                if (s != "gome") {
                    $("#warmTips").css("display", "block");
                    $("#warmTips span").text("您输入的可能为合作账户昵称，点击该站点登录");
                    $("#corp_" + s).addClass("current")
                } else {
                    $("#warmTips").css("display", "block");
                    $("#warmTips span").text("您输入的可能为账户的昵称，昵称不可用于登录")
                }
                $("#snsUrl").hide();
                $("#warmTips").show()
            } else if (s != "gome") {
                if (snsNameHash[s] != undefined && snsUrlHash[s] != undefined) {
                    if (a) {
                        $("#warmTips span").text("该邮箱为" + snsNameHash[s] + "合作账户绑定，请点击该站点")
                    } else if (t) {
                        $("#warmTips span").text(snsNameHash[s] + "联合账户已绑定此号码，")
                    } else {
                        $("#warmTips span").text("该账户为" + snsNameHash[s] + "合作账户，请点击该站点")
                    }
                    $("#snsUrl").attr("href", snsUrlHash[s]);
                    $("#warmTips").show();
                    $("#snsUrl").show();
                    $("#corp_" + s).addClass("hover")
                } else if (s == "hqm" && e.substring(0, 4) == "hqm-") {
                    var n = "请去掉“hqm-”，使用门店会员卡号登录";
                    $("#warmTips span").text(n);
                    $("#snsUrl").hide();
                    $("#snsUrl").attr("href", "#");
                    $("#warmTips").show()
                }
            }
        }})
}
var snsUrlHash = {qq: "/quicklogin/qqLogin.no", netease: "/quicklogin/neteaseLogin.no", renren: "/quicklogin/renrenLogin.no", sina: "/quicklogin/sinaLogin.no", kaixin: "/quicklogin/kaixinLogin.no", qihoo: "/quicklogin/qihooLogin.no", baidu: "/quicklogin/baiduLogin.no", alipay: "/quicklogin/alipayLogin.no"};
var snsNameHash = {qq: "QQ", netease: "网易", renren: "人人网", sina: "新浪微博", kaixin: "开心网", qihoo: "360", baidu: "百度", alipay: "支付宝"};
function validateLoginCaptcha() {
    var e = $("#authenticCodeForLogin").val();
    var r = $("#loginName").val();
    var i = $("#captchaUUID").val();
    var s = $("input[name='gomeOrCoo8']:checked").val();
    if ("coo8" == s) {
        r = $.trim(r) + "@coo8"
    }
    if (e != null && e.length == 4) {
        isShowFindPassword = false;
        var a = contextPath + "/toValidateLoginCaptcha.no";
        $.ajax({type: "post", url: a, data: {loginName: r, authenticCode: e, captchaUUID: i, captchaGrade: captchaGrade}, success: function(e) {
                var r = $.trim(e.result);
                if (r == "success") {
                    $("#verify_tips").show();
                    $("#verify_tips b").removeClass("error");
                    $("#verify_tips b").addClass("current")
                } else if (r != "unchecked") {
                    if (r == "fail") {
                        $("#err-tip p").html("验证码错误，请重新输入");
                        $("#err-tip").show()
                    } else if (r == "invalid") {
                        $("#err-tip p").html("验证码已过期，请重新输入");
                        $("#err-tip").show()
                    } else {
                        $("#err-tip p").html("系统忙，请刷新页面再试");
                        $("#err-tip").show()
                    }
                    $("#target-pic").addClass("pic-wrap pic-wrap-high");
                    $("#authenticCodeForLogin").addClass("txt-error");
                    $("#verify_tips").show();
                    $("#verify_tips b").removeClass("current");
                    $("#verify_tips b").addClass("error");
                    $("#frm #authenticCodeForLogin").blur()
                } else {
                    $("#err-tip p").html("验证码系统忙，请刷新页面再试");
                    $("#err-tip").show();
                    $("#target-pic").addClass("pic-wrap pic-wrap-high");
                    $("#authenticCodeForLogin").addClass("txt-error");
                    $("#verify_tips").show();
                    $("#verify_tips b").removeClass("current");
                    $("#verify_tips b").addClass("error");
                    $("#frm #authenticCodeForLogin").blur()
                }
                if (isShowFindPassword) {
                    $(".findpassword").show()
                } else {
                    $(".findpassword").hide()
                }
            }})
    }
}
function detectCapsLock(e) {
    var r = e || window.event;
    var i = r.keyCode || r.which;
    var s = r.shiftKey || i == 16 || false;
    if (i >= 65 && i <= 90 && !s || i >= 97 && i <= 122 && s) {
        $("#capital_tip").show()
    } else {
        $("#capital_tip").hide()
    }
}